package com.bjsxt.controller.erp;

import com.bjsxt.aspectj.annotation.Log;
import com.bjsxt.aspectj.enums.BusinessType;
import com.bjsxt.controller.BaseController;
import com.bjsxt.dto.ProviderDto;
import com.bjsxt.service.ProviderService;
import com.bjsxt.utils.ShiroSecurityUtils;
import com.bjsxt.vo.AjaxResult;
import com.bjsxt.vo.DataGridView;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author:liao
 * @Description:TODO
 * @date:2020/12/21
 */
@RestController
@RequestMapping("erp/provider")
public class ProviderController extends BaseController {

    @Reference
    private ProviderService providerService;

    //分页查询
    @GetMapping("listProviderForPage")
    @HystrixCommand
    public AjaxResult listProviderForPage(ProviderDto providerDto){
        DataGridView dataGridView = providerService.listProviderPage(providerDto);
        return AjaxResult.success("查询成功",dataGridView.getData(),dataGridView.getTotal());
    }

    //增加
    @PostMapping("addProvider")
    @HystrixCommand
    @Log(title = "增加供应商信息",businessType = BusinessType.INSERT)
    public AjaxResult addProvider(@Validated ProviderDto providerDto){
        providerDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(providerService.insertProvider(providerDto));
    }

    //修改
    @PutMapping("updateProvider")
    @HystrixCommand
    @Log(title = "修改供应商信息",businessType = BusinessType.UPDATE)
    public AjaxResult updateProvider(@Validated ProviderDto providerDto){
        providerDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(providerService.updateProvider(providerDto));
    }

    // 删除
    @DeleteMapping("deleteProviderByIds/{providerIds}")
    @Log(title = "删除供应商信息",businessType = BusinessType.DELETE)
    @HystrixCommand
    public AjaxResult deleteProviderByIds( @PathVariable Long[] providerIds){
        return AjaxResult.toAjax(providerService.deleteProvider(providerIds));
    }

    // 根据id查询供应商信息
    @GetMapping("getProviderById/{providerId}")
    @HystrixCommand
    public AjaxResult getProviderById(@PathVariable Long providerId){
        return AjaxResult.success(providerService.getOne(providerId));
    }

    // 查询有效的供应商信息
    @GetMapping("selectAllProvider")
    @HystrixCommand
    public AjaxResult selectAllProvider(){
        return AjaxResult.success(providerService.selectAllProvider());
    }

}
